﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 射击游戏.baseclass;

namespace 射击游戏
{
    public partial class Form1 : Form
    {
        private Bitmap bankground;//背景图片资源
        private Bitmap bmPaddle;//挡板图片资源
        private Bitmap bmBlock;//砖块图片资源
        private Bitmap bmBall;//弹球图片资源

        private static readonly Rectangle GamePaddleRect
           = new Rectangle(39, 1, 93, 23);//挡板资源在合图中的矩形位置
        private static readonly Rectangle GameBlockRect
           = new Rectangle(139, 1, 62, 27);//砖块资源在合图中的矩形位置
        private static readonly Rectangle GameBallRect
           = new Rectangle(1, 1, 36, 36);//弹球资源在合图中的矩形位置
        private Point centerOfPaddle;//挡板中心位置
        private Rectangle paddleRect;//挡板的位置
        public Form1()
        {
            InitializeComponent();
        }
        private void loadpicture()//载入图片

        {
            bankground = bitmaphelps.LoadBm("Background");
            Bitmap bmBreak = bitmaphelps.LoadBm("Break");
            //从"break.bmp"合图中的指定位置复制挡板图片资源
            bmPaddle = bmBreak.Clone(GamePaddleRect, bmBreak.PixelFormat);
            //从"break.bmp"合图中的指定位置复制砖块图片资源
            bmBlock = bmBreak.Clone(GameBlockRect, bmBreak.PixelFormat);
            //从"break.bmp"合图中的指定位置复制弹球图片资源
            bmBall = bmBreak.Clone(GameBallRect, bmBreak.PixelFormat);

        }
        protected override void OnPaint(PaintEventArgs e)
        {
            //1.在内存中建立绘制区域
            Bitmap bufferBm = new Bitmap(this.ClientRectangle.Width - 1,
                this.ClientRectangle.Height - 1);
            Graphics g = Graphics.FromImage(bufferBm);
            //2.在内存中绘制所有图片资源
            this.DrawGame(g);
            //3.把内存中的区域一次性绘制在屏幕上
            e.Graphics.DrawImage(bufferBm, 0, 0);
            //4.释放当前内存区域
            g.Dispose();
            base.OnPaint(e);
        }
        private void DrawGame(Graphics g)//游戏界面绘制
        {
            //绘制背景
            g.DrawImage(bankground,
                new Rectangle(0, 0,
                this.ClientRectangle.Width - 1,
                this.ClientRectangle.Height - 1));
            //绘制挡板 宽度：93 ，高度: 23
            g.DrawImage(bmPaddle,
                new Rectangle(centerOfPaddle.X - 93 / 2, centerOfPaddle.Y, 93, 23)
                );
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.loadpicture();
        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void Form1_MouseClick(object sender, MouseEventArgs e)
        {

        }
    }
}
